//% color="#FF6B35" iconWidth=50 iconHeight=40
namespace TCS34725_ColorSensor {
    
    //% block="TCS34725 Init with integration time [TIME] and gain [GAIN]" blockType="command"
    //% TIME.shadow="dropdown" TIME.options="INTEGRATION_TIME"
    //% GAIN.shadow="dropdown" GAIN.options="SENSOR_GAIN"
    export function tcs34725Init(parameter: any, block: any) {
        let time = parameter.TIME.code;
        let gain = parameter.GAIN.code;
        Generator.addInclude("TCS34725_Init", "#include <Wire.h>");
        Generator.addInclude("TCS34725_Library", "#include \"Adafruit_TCS34725.h\"");
        Generator.addObject("TCS34725_Object", "Adafruit_TCS34725", `tcs(${time}, ${gain});`);
        Generator.addSetup("TCS34725_Setup", `
  if (tcs.begin()) {
    Serial.println("Found sensor");
  } else {
    Serial.println("No TCS34725 found ... check your connections");
    while (1);
  }`);
    }

    //% block="---"
    export function noteSep1() {}

    //% block="Read raw RGBC data" blockType="command"
    export function readRawData(parameter: any, block: any) {
        Generator.addCode(`uint16_t r, g, b, c;
  tcs.getRawData(&r, &g, &b, &c);`);
    }

    //% block="Get raw [COLOR] value" blockType="reporter"
    //% COLOR.shadow="dropdown" COLOR.options="RAW_COLORS"
    export function getRawValue(parameter: any, block: any) {
        let color = parameter.COLOR.code;
        Generator.addCode([`${color}`, Generator.ORDER_ATOMIC]);
    }
    //% block="Calculate RGB values (0-255)" blockType="command"
    export function calculateRGB(parameter: any, block: any) {
        Generator.addCode(`float red, green, blue;
  tcs.getRGB(&red, &green, &blue);`);
    }
    //% block="Get RGB [RGB_COLOR] value (0-255)" blockType="reporter"
    //% RGB_COLOR.shadow="dropdown" RGB_COLOR.options="RGB_COLORS"
    export function getRGBValue(parameter: any, block: any) {
        let color = parameter.RGB_COLOR.code;
        Generator.addCode([`(int)${color}`, Generator.ORDER_ATOMIC]);
    }



    // //% block="---"
    // export function noteSep2() {}

    // //% block="Calculate color temperature" blockType="reporter"
    // export function getColorTemperature(parameter: any, block: any) {
    //     Generator.addCode([`tcs.calculateColorTemperature_dn40(r, g, b, c)`, Generator.ORDER_UNARY_POSTFIX]);
    // }

    // //% block="Calculate lux value" blockType="reporter"
    // export function getLuxValue(parameter: any, block: any) {
    //     Generator.addCode([`tcs.calculateLux(r, g, b)`, Generator.ORDER_UNARY_POSTFIX]);
    // }

    // //% block="---"
    // export function noteSep3() {}

    // //% block="Set integration time [TIME]" blockType="command"
    // //% TIME.shadow="dropdown" TIME.options="INTEGRATION_TIME"
    // export function setIntegrationTime(parameter: any, block: any) {
    //     let time = parameter.TIME.code;
    //     Generator.addCode(`tcs.setIntegrationTime(${time});`);
    // }

    // //% block="Set gain [GAIN]" blockType="command"
    // //% GAIN.shadow="dropdown" GAIN.options="SENSOR_GAIN"
    // export function setGain(parameter: any, block: any) {
    //     let gain = parameter.GAIN.code;
    //     Generator.addCode(`tcs.setGain(${gain});`);
    // }

    // //% block="---"
    // export function noteSep4() {}

    // //% block="Enable interrupt [ENABLE]" blockType="command"
    // //% ENABLE.shadow="dropdown" ENABLE.options="ENABLE_DISABLE"
    // export function setInterrupt(parameter: any, block: any) {
    //     let enable = parameter.ENABLE.code;
    //     Generator.addCode(`tcs.setInterrupt(${enable});`);
    // }

    // //% block="Clear interrupt" blockType="command"
    // export function clearInterrupt(parameter: any, block: any) {
    //     Generator.addCode(`tcs.clearInterrupt();`);
    // }

    // //% block="Set interrupt limits low [LOW] high [HIGH]" blockType="command"
    // //% LOW.shadow="number" LOW.defl="100"
    // //% HIGH.shadow="number" HIGH.defl="1000"
    // export function setInterruptLimits(parameter: any, block: any) {
    //     let low = parameter.LOW.code;
    //     let high = parameter.HIGH.code;
    //     Generator.addCode(`tcs.setIntLimits(${low}, ${high});`);
    // }

    // //% block="---"
    // export function noteSep5() {}

    // //% block="Enable sensor" blockType="command"
    // export function enableSensor(parameter: any, block: any) {
    //     Generator.addCode(`tcs.enable();`);
    // }

    // //% block="Disable sensor" blockType="command"
    // export function disableSensor(parameter: any, block: any) {
    //     Generator.addCode(`tcs.disable();`);
    // }
}
